﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace ToDoList.Entity.Models
{
    public partial class TodoContext : DbContext
    {
        public virtual DbSet<Inventory> Inventory { get; set; }
        public virtual DbSet<Matters> Matters { get; set; }
        public virtual DbSet<Users> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
            optionsBuilder.UseSqlServer(@"Data Source=.\sqlexpress;Initial Catalog=Todo;Integrated Security=True");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Inventory>(entity =>
            {
                entity.Property(e => e.CreationTime).HasColumnType("datetime");

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.HasOne(d => d.User)
                    .WithMany(p => p.Inventory)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK__Inventory__UserI__25869641");
            });

            modelBuilder.Entity<Matters>(entity =>
            {
                entity.Property(e => e.CreationTime).HasColumnType("datetime");

                entity.Property(e => e.MatterName)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.OverTime).HasColumnType("datetime");

                entity.Property(e => e.Reamrk).HasMaxLength(50);

                entity.HasOne(d => d.Inventory)
                    .WithMany(p => p.Matters)
                    .HasForeignKey(d => d.InventoryId)
                    .OnDelete(DeleteBehavior.Restrict)
                    .HasConstraintName("FK__Matters__Invento__286302EC");
            });

            modelBuilder.Entity<Users>(entity =>
            {
                entity.Property(e => e.Nickname)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.UserName)
                    .IsRequired()
                    .HasMaxLength(50);
            });
        }
    }
}